package com.bond.common;

import lombok.Data;

@Data
public class CommonResult<T> {

    private static final int SUCCESS = 0;
    private static final int ERROR = 500;

    private int code;

    private T data;

    private String msg;

    public static <T> CommonResult OK() {
        CommonResult result = new CommonResult();
        result.setCode(SUCCESS);
        result.setMsg("操作成功");
        return result;
    }

    public static <T> CommonResult OK(T data) {
        CommonResult result = new CommonResult();
        result.setCode(SUCCESS);
        result.setMsg("操作成功");
        result.setData(data);
        return result;
    }

    public static CommonResult FAIL() {
        CommonResult result = new CommonResult();
        result.setCode(ERROR);
        result.setMsg("操作失败");
        return result;
    }

    public static CommonResult FAIL(String msg) {
        CommonResult result = new CommonResult();
        result.setCode(ERROR);
        result.setMsg(msg);
        return result;
    }
}
